package game;

public class RockPaperScissors {
	public Result play(Player p1, Player p2) 
	{
		for (int i = 0; i < p1.getRPSEnumLength(); i++) 
		{
			switch (play(p1.getMove(), p2.getMove())) 
			{
				case WIN:
					p1.setPScore(p1.getPScore()+1);
					break;
				case LOST:
					p2.setPScore(p2.getPScore()+1);
					break;
				case TIE:
					p1.setPScore(p1.getPScore()+1);
					p2.setPScore(p2.getPScore()+1);
					break;
				default:
					break;
			}
		}
		
		if (p1.getPScore() > p2.getPScore())
		{
			return Result.WIN;
		}
		else if (p1.getPScore() == p2.getPScore())
		{
			return Result.TIE;
		}
		else
		{
			return Result.LOST;
		}
	}
	
	public Result play(RPSEnum p1, RPSEnum p2) 
	{
		switch (p1) 
		{
		case PAPER:
			switch (p2) 
			{
				case SCISSORS:
					return Result.LOST;
				case PAPER:
					return Result.TIE;
				case ROCK:
					return Result.WIN;
				default:
					return Result.LOST;
			}

		case SCISSORS:
			switch (p2) 
			{
				case SCISSORS:
					return Result.TIE;
				case PAPER:
					return Result.WIN;
				case ROCK:
					return Result.LOST;
				default:
					break;
			}
		
		case ROCK:
			switch (p2) 
			{
				case SCISSORS:
					return Result.WIN;
				case PAPER:
					return Result.LOST;
				case ROCK:
					return Result.TIE;
				default:
					return Result.LOST;
			}

		default:
			return Result.LOST;
		}
	}
}
